<template>
  <div>
    <div class="his-hot" v-show="isShowHistory">
      <div class="hd">
        <h3>历史记录</h3>
        <van-icon name="delete-o" @click="clearHistory" />
      </div>
      <div class="bd">
        <van-tag
          plain
          type="default"
          v-for="(item, index) in historyListData"
          :key="index"
          @click="tagClick(item)"
          >{{ item }}</van-tag
        >
      </div>
    </div>

    <div class="his-hot">
      <div class="hd">
        <h3>热门搜索</h3>
      </div>
      <div class="bd">
        <van-tag
          plain
          type="default"
          v-for="(item, index) in hotKeywordListData"
          :key="index"
          :class="item.is_hot == 1 ? 'red' : ''"
          @click="tagClick(item.keyword)"
          >{{ item.keyword }}</van-tag
        >
      </div>
    </div>
  </div>
</template>

<script>
import { ClearHistory } from "@/request/api";
export default {
  data() {
    return {
      isShowHistory: true
    };
  },
  props: ["historyListData", "hotKeywordListData"],
  methods: {
    tagClick(val) {
      console.log(val);
      this.$emit("tagClick", val);
    },
    clearHistory() {
      ClearHistory().then(res => {
        if (res.errno == 0) {
          this.$toast.success("删除成功");
          //隐藏历史记录的这个盒子
          setTimeout(() => {
            this.isShowHistory = false;
          }, 1000);
        }
      });
    }
  }
};
</script>
 
<style lang = "less" scoped>
.his-hot {
  background-color: #fff;
  padding: 0.1rem;
  margin-bottom: 0.2rem;
  .hd {
    display: flex;
    justify-content: space-between;
    font-size: 0.2rem;
    margin-bottom: 0.05rem;
  }
  .van-tag {
    margin-right: 0.05rem;
    padding: 0.03rem;
  }
  .red {
    color: red;
  }
}
</style>